import { $post,$setToken} from "../utils/request"
import md5 from 'js-md5'
import { message } from "ant-design-vue"

// 登录api
export const $login =async(params) => {
  // 对密码进行加密
    params.password = md5(md5(params.password).split('').reverse().join(''))
    let data = await $post('login',params)
  let {success,msg} = data
  if(success) {
    let {token} = data
    // 将token保存在浏览器缓存中
    sessionStorage.getItem('token',token)
    // 在请求投头中更新信息
    $setToken(token)
    message.success(msg)
  }else {
    message.error(msg)
  }
  return success
}